package com.titaniume.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ProjectName: juc
 * @Package: com.titaniume.pool
 * @ClassName: ThreadPoolDemo2
 * @Author: titan
 * @Description: 自定义线程池  银行办理业务
 * @Date: 2021/11/27 9:55
 * @Version: 1.0
 */
public class ThreadPoolDemo2 {

    public static void main(String[] args) {


        //定时线程次:线程数量为 5---窗口数为 5
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                5,
                10,
                2L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        try {
            //10 个办理业务
            for (int i = 1; i <= 10; i++) {
                poolExecutor.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + " 窗口,办理业务");
                });
            }
        } finally {
            poolExecutor.shutdown();
        }

    }

}
